<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8" />
    <title>智慧社区-物业管理</title>

    <meta name="description" content="Dashboard" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/resource/assets/img/favicon.png" type="image/x-icon">

    <!--Basic Styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/font-awesome.min.css" rel="stylesheet" />

    <!--Beyond styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/beyond.min.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/animate.min.css" rel="stylesheet" />
<script src="${pageContext.request.contextPath}/resource/assets/js/skins.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/ckeditor/ckeditor.js"></script>
</head>
<body>
<%@include file="../header.jsp" %>
	<!-- Main Container -->
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">
            <!-- Page Sidebar -->
            <%@include file="../nav.jsp" %><!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb" style="margin-top: 8px;">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="#">首页</a>
                        </li>
                        <li><a href="#">周边商铺</a></li>
                        <li class="active">添加商铺</li>
                    </ul>
                </div><!-- /Page Breadcrumb -->
                <!-- Page Header -->
                <div class="page-header position-relative">
                    <div class="header-title" style="margin-top: 2px;">
                        <h1>
                            添加商铺
                        </h1>
                    </div><!--Header Buttons-->
                    <div class="header-buttons">
                        <a class="sidebar-toggler" href="#">
                            <i class="fa fa-arrows-h"></i>
                        </a>
                        <a class="refresh" id="refresh-toggler" href="">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                        <a class="fullscreen" id="fullscreen-toggler" href="#">
                            <i class="glyphicon glyphicon-fullscreen"></i>
                        </a>
                    </div><!--Header Buttons End-->
                </div><!-- /Page Header -->
                <!-- Page Body -->
                <div class="page-body">
                	<div class="row">
	                	<div class="col-lg-6 col-sm-6 col-xs-12">
	                		<div class="widget">
                                        <div class="widget-header bordered-bottom bordered-palegreen">
                                            <span class="widget-caption">添加商铺</span>
                                        </div>
                                        <div class="widget-body">
                                           <div id="registration-form">
                                                        <form role="form">
                                                            <div class="form-title">
                                                            	商铺信息
                                                            </div>
                                                            	<div class="form-group">
                                                                        <span class="input-icon icon-right">
                                                                            <input type="text" class="form-control" placeholder="所属小区" value="${loginUser.loginVillage.name}" disabled>
                                                                            <i class="glyphicon glyphicon-globe"></i>
                                                                       </span>
                                                              	</div>
                                                              	<div class="form-group">
                                                                 <select id="type" style="width:100%;">
                                                                 	<option value="0"> 商铺类型</option>
                                                                 		<option value="1"> 餐饮 </option>
												                          <option value="2"> 服装 </option>
												                          <option value="3"> 娱乐 </option>
												                          <option value="4"> 母婴 </option>
												                          <option value="5"> 美容 </option>
												                          <option value="6"> 数码 </option>
												                          <option value="7"> 百货</option>
												                          <option value="8"> 其他</option>
                                            						</select>
                                                            </div>
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="name" type="text" class="form-control"  placeholder="商铺名称" value="${shop.subject }">
                                                                    <i class="glyphicon glyphicon-align-right"></i>
                                                                </span>
                                                            </div>
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                	<textarea class="form-control" rows="10" id="content" placeholder="商铺概要，简要描述商铺经营范围、特色等等 ..."></textarea>
                                                                     <script>CKEDITOR.replace( 'content',{height:'300px',filebrowserUploadUrl:'${pageContext.request.contextPath}/ckeditorUpload'} );</script>
                                                         		</span>
                                                            </div>
                                                             <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="address" type="text" class="form-control" placeholder="地址" value="${shop.address }">
                                                                    <i class="glyphicon glyphicon-map-marker"></i>
                                                                </span>
                                                            </div>
                                                             <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="contacts" type="text" class="form-control" placeholder="联系人" value="${shop.contacts }">
                                                                    <i class="glyphicon glyphicon-map-marker"></i>
                                                                </span>
                                                            </div>
                                                          <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="number" type="text" class="form-control" placeholder="联系电话" value="${shop.phoneNumber }">
                                                                    <i class="glyphicon glyphicon-map-marker"></i>
                                                                </span>
                                                            </div>
                                                              <div class="form-group">
											                      <label for="fileUpload">上传图片(单选)</label>
											                      <input type="file" id="fileUpload" name="upload">
											                      <p class="help-block">此处可以添加商铺列表的展示图片.</p>
											                    </div>      
                                                            <hr class="wide" />
                                                            <div class="row" style="text-align: right;margin-right: 10px;">
                                                            	<button type="button" class="btn btn-warning" onclick="cancel()"> 取 消 </button>
                                                            	<button type="button" class="btn btn-blue" onclick="save()"> 添 加 </button>
                                                            </div>
                                                            
                                                        </form>
                                                    </div> 
                                        </div>
                                    </div>
	                	</div>
                	
                    </div>
                </div><!-- /Page Body -->
             </div><!-- /Page Content -->
     	</div><!-- /Page Container -->
     </div><!-- /Main Container -->
     	<script src="${pageContext.request.contextPath}/resource/assets/js/jquery-2.0.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/beyond.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/select2/select2.js"></script>
<script src="${pageContext.request.contextPath}/resource/assets/js/ajaxfileupload.js"></script>
    <!--Beyond Scripts-->
    
    <script type="text/javascript">
    	$('.loading-container').hide();
    	$('#menu_shop').addClass("active open");
    	$('#menu_shopadd').addClass("active");
    	$('#type').select2();
    	var objectId = "${shop.objectId}";
    	if(objectId != ""){
    		$('#type').val("${shop.type}").trigger("change");
   		}
    	var editSummary = "${shop.summary }";
    	$(function(){
    		CKEDITOR.instances.content.setData(decodeURIComponent(editSummary));
    	});
    	
    	function save(){
    		var type = $('#type').val();
    		var subject = $('#name').val();
    		var summary = CKEDITOR.instances.content.getData();
    		var address = $('#address').val();
    		var contacts = $('#contacts').val();
    		var phoneNumber = $('#number').val();
    		
    		
    		if ($.trim(subject) == "" || $.trim(summary) == "" || $.trim(address) == "" || $.trim(contacts) == "" || $.trim(phoneNumber) == "") {
    			alert("请完善商铺信息后再提交保存");
    			return;
    		}
    		var encodeContent = encodeURIComponent(summary);
    		console.log(encodeContent);
    		$('.loading-container').show();
    		$.ajaxFileUpload({
    			"url":"${pageContext.request.contextPath}/shop_save",
    			secureuri: false,
    			"data":{objectId:objectId,type:type,subject:subject,summary:encodeContent,address:address,contacts:contacts,phoneNumber:phoneNumber},
    			fileElementId: 'fileUpload',
    			"dataType":'json',
    			"success" : function(result) {
    				$('.loading-container').hide();
    				alert("商铺信息保存成功");
					cancel();
    			},
    			"error" : function(msg) {
    				alert("error msg:"+msg.responseText);
    			}
    		});
    	}
    	
    	function cancel(){
    		$('#name').val("");
        	$('#summary').val("");
        	$('#address').val("");
        	$('#contacts').val("");
        	$('#number').val("");
        	CKEDITOR.instances.content.setData("");
    	}
    	
    	
    </script>
</body>
</html>